<template>
    <div class="generateSharePassword">
        <div class="banner">
            <div class="password">
                {{ generateSharePassword }}
            </div>
        </div>
        <div class="tips">
            点击右上角分享给好友
        </div>
    </div>
</template>

<script>

    import wx from "weixin-js-sdk"
    import { post,basePrefix, getCookie, getStorageObj } from "../../js/utils"
    import qs from 'qs'

    export default {
        name: 'GenerateSharePassword',
        components: {
        },
        data () {
            return {
                generateSharePassword: this.$route.query.generateSharePassword,
            }
        },
        created () {
            let param = {
                generateSharePassword: this.generateSharePassword
            }
            let jsApiTicket = JSON.parse(Base64.decode(getCookie("jsapiTicket")))
            if(this.$route.query.enter  == 'remoteSharePassword'){
                Object.assign(param,{appId: jsApiTicket.AppId,type: 'generateSharePassword'})
                wx.config({
                    debug: false,
                    beta: true,
                    appId: jsApiTicket.AppId,
                    timestamp: jsApiTicket.Timestamp,
                    nonceStr: jsApiTicket.NonceStr,
                    signature: jsApiTicket.Signature,
                    jsApiList: [
                        'checkJsApi',
                        'updateAppMessageShareData',
                        'onMenuShareAppMessage'
                    ]
                })
                wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
                    wx.updateAppMessageShareData({
                        title: '远程分享密码', // 分享标题
                        desc: '你有一个远程分享密码', // 分享描述
                        link: window.location.href.split("?")[0] + "?" + qs.stringify(param), // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: '', // 分享图标
                        success: function () {
                            // 设置成功
                        }
                    })
                    wx.onMenuShareAppMessage({
                        title: '远程分享密码', // 分享标题
                        desc: '你有一个远程分享密码', // 分享描述
                        link: window.location.href.split("?")[0] + "?" + qs.stringify(param), // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: '', // 分享图标
                        type: '', // 分享类型,music、video或link，不填默认为link
                        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                        success: function () {
                            // 用户点击了分享后执行的回调函数
                        }
                    })
                });
            }

        },
        methods: {
            init: function(){

            }
        }
    }
</script>

<style scoped>
    .generateSharePassword > .banner {
        display: flex;
        justify-content: center;
    }

    .generateSharePassword > .banner > .password{
        width: 90vw;
        height: 30vh;
        background: url(../../assets/GenerateSharePassword_01.png) no-repeat center center;
        background-size: 100% auto;
        text-align: center;
        line-height: 30vh;
        color: #fff;
        font-size: 8vh;
    }

    .generateSharePassword > .tips {
        color: rgba(120, 120, 120, 1);
    }
</style>
